import React from 'react';
import OperaPrompt from '@/components/OperaPrompt';
import { Form, Input, DatePicker, message } from 'antd';
import request from '@/utils/request';

const save = (props: any) => {
  const { form, close, getList, id } = props;
  
  const onFinish = (values: any) => {
    values['start_time'] = values['start_time'].format('YYYY-MM-DD HH:mm:ss');
    values['end_time'] = values['end_time'].format('YYYY-MM-DD HH:mm:ss');
    request(`/promote/sec-kill/activity/${id}`, {
      method: 'POST',
      data: { ...values },
    }).then((result) => {
      message.success(result.message, 1, () => {
        getList();
        close();
      });
    });
  };

  return (
    <div>
      <OperaPrompt
        dataList={[
          '秒杀时段名称将会显示在秒杀列表页的时间段内',
          '秒杀时间-时：可填入00-23的整数（如果为个位数，需在前面加上0，比如：01）',
          '秒杀时间-分/秒：可填入00-59的整数（如果为个位数，需在前面加上0，比如：01）',
        ]}
      />
      <Form
        form={form}
        labelCol={{ span: 5 }}
        wrapperCol={{ span: 17 }}
        style={{ marginTop: '8px' }}
        onFinish={onFinish}
      >
        <Form.Item
          label="秒杀时间段名称"
          name="title"
          required
          rules={[{ required: true, message: '主营行业名称不能为空' }]}
        >
          <Input />
        </Form.Item>
        <Form.Item label="开始时间" name="start_time" required
          rules={[{ required: true, message: '开始时间不能为空' }]}
        >
          <DatePicker format="YYYY-MM-DD HH:mm:ss" showTime />
        </Form.Item>
        <Form.Item label="结束时间" name="end_time" required
          rules={[{ required: true, message: '结束时间不能为空' }]}
        >
          <DatePicker format="YYYY-MM-DD HH:mm:ss" showTime />
        </Form.Item>
      </Form>
    </div>
  );
};

export default save;

